package restaurant;

import restaurant.iterators.Iterator;

/**
 * The Class cmdMenuByPrepTime.
 * 
 * @author Ebonie
 */

public class cmdMenuByPrepTime implements Command
{

	/** The info. */
	private InformationAggregator info;

	/** The prep time. */
	private int prepTime;



	/**
	 * Instantiates a new cmd menu by prep time.
	 * 
	 * @param info the info
	 * @param prepTime the prep time
	 */
	public cmdMenuByPrepTime(InformationAggregator info, int prepTime) {
		this.info = info;
		this.prepTime = prepTime;
	}



	/**
	 * Execute.
	 * 
	 * @return the menu by preparation time.
	 * @see restaurant.Command#execute()
	 */
	@Override
	public Object execute()
	{
		Menu menu = info.getMenu();
		Iterator prepIterator = menu.getByPrepTimeIterator(prepTime);
		MenuItem item;
		Menu prepTimeMenu = new Menu();

		while (prepIterator.hasNext()) {
			item = (MenuItem) prepIterator.next();

			if (item.isAvailable())
				prepTimeMenu.add(item);
		}

		return prepTimeMenu;
	}

}
